package chapter4.No4_1_使用reentrantLock类.demo8;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * !
 *
 * @author liujian
 * @version 2016/11/21 0021
 */
public class P {

    ReentrantLock lock;
    Condition conditionP;
    Condition conditionC;

    public P(ReentrantLock lock, Condition conditionP, Condition conditionC) {
        this.lock = lock;
        this.conditionP = conditionP;
        this.conditionC = conditionC;
    }

    public void sc() throws InterruptedException {
        lock.lock();
        while (Tools.count > 0) {
            System.out.println("还有没消费的，生产者线程进入waiting状态");
            conditionP.await();
        }
        Thread.sleep(500);
        Tools.count = 1;
        System.out.println("生产了一个★,count=" + Tools.count);
        conditionC.signal();
        lock.unlock();
    }

}
